package day22_3;

import java.util.LinkedList;
import java.util.Queue;

/**
 * @ClassName Solution
 * @Description TODO
 * @Author clockTown
 * @Date 2021/5/31 19:54
 * @Version 1.0
 */
public class Solution {

    public static int lengthOfLongestSubstring(String s) {
        if (s == null || s.length() <= 0) {
            return 0;
        }

        int count = 0;

        Queue queue = new LinkedList<Character>();


        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (queue.contains(c)){
                count = Math.max(count, queue.size());
                while (!queue.peek().equals(c)){
                    queue.poll();
                }
                queue.poll();
                queue.offer(c);
            }else {
                queue.offer(c);
            }
        }


        return count;
    }

    public static void main(String[] args) {
        String s = "au";
        int res = lengthOfLongestSubstring(s);
        System.out.println(res);
    }
}
